#pragma once

#include "lg_conf.h"

#define LG_PI 3.141592653589f

typedef struct {
    LGFloat x, y, z;
}LGVec2;

typedef struct {
    LGFloat x, y;
}LGVec3;

typedef struct {
    LGFloat x, y, z, w;
}LGVector;

typedef union {
    LGFloat B[16];
    struct {
        LGFloat a11, a21, a31, a41,
                a12, a22, a32, a42,
                a13, a23, a33, a43,
                a14, a24, a34, a44;
    } A;
    LGVector V[4];
}LGMatrix;

LG_API LGFloat
lgDotVector(LGVector * v1, LGVector * v2);
LG_API LGFloat
lgDotVector2D(LGVector * v1, LGVector * v2);
LG_API void
lgCrossVector(LGVector * res, LGVector * v);

LG_API void
lgNormalizeVector(LGVector* v);
LG_API void
lgNormalizeVector2D(LGVector* v);

LG_API LGFloat
lgLengthVector(LGVector* v);
LG_API LGFloat
lgLengthVector2D(LGVector* v);

LG_API void
lgAddVector(LGVector *res, LGVector* add);
LG_API void
lgAddVector2D(LGVector *res, LGVector* add);

LG_API void
lgSubVector(LGVector* res, LGVector* sub);

LG_API void
lgSubVector2D(LGVector* res, LGVector* sub);

LG_API LGFloat
lgDistanceVector(LGVector *v1, LGVector * v2);
LG_API LGFloat
lgDistanceVector2D(LGVector *v1, LGVector * v2);



LG_API void
lgIdentityMatrix(LGMatrix* res);
LG_API void
lgIdentityMatrix2D(LGMatrix* res);

LG_API void
lgMulMatrix(LGMatrix* res, LGMatrix* mul);
LG_API void
lgMulMatrix2D(LGMatrix* res, LGMatrix* mul);

LG_API void
lgMoveMatrix(LGMatrix* res, LGVector* v);
LG_API void
lgMoveMatrix2D(LGMatrix* res, LGVec2* v);

LG_API void
lgScaleMatrix(LGMatrix* res, LGVector* v);
LG_API void
lgScaleMatrix2D(LGMatrix* res, LGVec2* v);

LG_API void
lgRotateMatrix(LGMatrix* res, LGVector* v);
LG_API void
lgRotateMatrix2D(LGMatrix* res, LGFloat radian);
LG_API void
lgRotateMatrixV(LGMatrix* res, LGVector* v, LGFloat radian);

LG_API void
lgPerspectiveMatrix(LGMatrix* res,
    LGFloat fov, LGFloat aspect, LGFloat near, LGFloat far);
LG_API void
lgOrthoMatrix(LGMatrix* res, LGFloat left, LGFloat right,
        LGFloat bottom, LGFloat top, LGFloat near, LGFloat far);

LG_API void
lgVectorMulMatrix(LGVector* res, LGMatrix* m);
LG_API void
lgVectorMulMatrixW(LGVector* res, LGMatrix* m, LGFloat w);
LG_API void
lgVectorMulMatrix2D(LGVector* res, LGMatrix* m);
LG_API void
lgVectorMulMatrix2DW(LGVector* res, LGMatrix* m, LGFloat w);

LG_API LGFloat
lgRadians(LGFloat degrees);
LG_API LGFloat
lgDegrees(LGFloat radian);

LG_API void
lgLookAt(LGMatrix* res, LGVector* eye, LGVector* center, LGVector* up);